using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Lesson21Work : MonoBehaviour
{
    // Start is called before the first frame update
    LineRenderer line;
    void Start()
    {
        //DrawCircle(new Vector3(0, 0, 0), 10, 360);
        
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            GameObject obj = new GameObject();
            line = obj.AddComponent<LineRenderer>();
            line.loop = false;
            line.startWidth = 0.5f;
            line.endWidth = 0.5f;
            line.positionCount = 0;
        }
        if (Input.GetMouseButton(0))
        {
            Vector3 nowPos= Input.mousePosition;
            nowPos.z = 10;
            line.positionCount += 1;
            line.SetPosition(line.positionCount - 1, Camera.main.ScreenToWorldPoint(nowPos));
        }

    }
    public void DrawCircle(Vector3 centerpos,float r,int posnum)
    {
        GameObject obj = new GameObject();
        obj.name = "R";
        LineRenderer line = obj.AddComponent<LineRenderer>();
        line.loop = true;
        line.positionCount = posnum;
        float angle=360f/posnum;
        for(int i=0;i<posnum;i++)
        {
            line.SetPosition(i, Quaternion.AngleAxis(angle * i, Vector3.up) * (centerpos + Vector3.forward * r));
        }
    }
}
